/**
 * @file Joystick.h
 * @author SoBigDog (623644973lubin@163.com)
 * @brief 
 * @version 0.1
 * @date 2020-09-25
 * 
 * @copyright Copyright (c) 2020
 * 
 */
#ifndef _JOYSTICK_H
#define _JOYSTICK_H

#include <stdbool.h>
#include "main.h"

#define PI		3.141592653589793f

extern uint32_t ADC_buff[50];

/**
 * @brief 
 * 
 */
struct float_joystick_config {
	float zero_offsetX;
	float zero_offsetY;
	float invalid_rangeX;
	float invalid_rangeyY;
};

struct joystick_config {
	int16_t zero_offsetX;		/* X向零位偏移 */
	int16_t zero_offsetY;		/* Y向零位偏移 */
	int16_t invalid_rangeX;		/* X向零位阈值 */
	int16_t invalid_rangeY;		/* Y向零位阈值 */
	int16_t max_valueX;			/*  */
	int16_t min_valueX;			/*  */
	int16_t max_valueY;			/*  */
	int16_t min_valueY;			/*  */

};

struct struct_vector {
	float   angle;
	float   value;
};

struct Joystick {
	struct struct_vector	Vector;
	struct joystick_config	Config;
	uint8_t					u8ChannelX;
	uint8_t					u8ChannelY;
	int16_t					u16AverageX;
	int16_t					u16AverageY;
	float					u16VelotageX;
	float					u16VelotageY;
};

void JoystickInit(struct Joystick * pJoy);
bool JoystickUpdate(struct Joystick * pJoy);

#endif


